<?php
$maxwight = get_shiping_max_weight();
$shipingprice = get_shiping_price();
$priceforunit = get_shiping_price_for_unit();
?>
<?php if (isset($notactive_owner)) { ?>
    <h1><span class="ico_signin"></span><?= lang('label_menu_link_mystore') ?></h1>

    <ul class="breadcrumb">
        <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
        <li><a href="<?= base_url('index/stores') ?>"><?= lang('label_menu_link_stores') ?></a></li>
        <li><?= lang('label_menu_link_mystore') ?></li>
    </ul>
    <div class="page">
        <div class="unsaved">
            <img src="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/images/unsaved.png" alt="" />
            <br /><?= lang('message_store_not_active') ?>
        </div>
        <br /><br /><br /><br />
    </div>
<?php } elseif (isset($notactive)) {
    ?>
    <h1><span class="ico_signin"></span><?= lang('label_menu_link_wrong_link') ?></h1>
    <div class="page">
        <ul class="breadcrumb">
            <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
            <li><a href="<?= base_url('index/stores') ?>"><?= lang('label_menu_link_stores') ?></a></li>
            <li><?= lang('label_menu_link_wrong_link') ?></li>
        </ul>
        <div class="unsaved">
            <img src="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/images/unsaved.png" alt="" />
            <br /><?= lang('message_store_wrong_link') ?>
        </div>
        <br /><br /><br /><br />
    </div>
<?php } else {
    ?>
    <?php
    if (isset($storedetails) && $storedetails) {
        $values = unserialize($store->package_values);
        ?>

        <h1><span></span><?php
            foreach ($storedetails as $stdetails)
                if ($stdetails->name == 'storename')
                    echo $sname = $stdetails->value
                    ?></h1>

        <ul class="breadcrumb">
            <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
            <?php if (isset($owner)) { ?>
                <li><a href="<?= base_url('user/profile') ?>"><?= lang('label_profile') ?></a></li>
            <?php } else { ?>
                <li><a href="<?= base_url('index/stores') ?>"><?= lang('label_menu_link_stores') ?></a></li>
            <?php } ?>
            <li><?= $sname ?></li>
        </ul>


        <div class="page">
            <div class="store_header">

                <div class="store_logo">
                    <h2><?= $sname ?></h2>
                    <?php if ($values['storedescription'] == 'true') { ?>
                        <?php
                        foreach ($storedetails as $stdetails)
                            if ($stdetails->name == 'storedescription') {
                                ?>
                                <p><span></span><?php
                                    echo $sdescr = $stdetails->value
                                    ?><samp></samp></p>
                                <?php
                            }
                    }
                    else
                        $sdescr = '';
                    ?>
                </div>


                <?php if ($values['storebanner'] == 'banner') { ?>
                    <div class="store_slider">
                        <span><img style="width: 100%; height: 100%" src="<?php
                            foreach ($storedetails as $stdetails)
                                if ($stdetails->name == 'storebanner_1')
                                    echo base_url(STORE_PATH . $stdetails->value)
                                    ?>" alt="" /></span>
                    </div>
                <?php }elseif ($values['storebanner'] == 'slider') { ?>
                    <?php
                    $content = '';
                    foreach ($storedetails as $stdetails) {
                        if (in_array($stdetails->name, array('storebanner_1', 'storebanner_2', 'storebanner_3'))) {

                            $content .= '<li><img style="width: 100%; height: 100%" src="' . base_url(STORE_PATH . $stdetails->value) . '" alt="" /></li>';
                        }
                    }
                    ?>
                    <?php if ($content != '') { ?>
                        <div class="store_slider">
                            <script src="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/js/jquery.bxslider.min.js"></script>
                            <link href="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/css/jquery.bxslider.css" rel="stylesheet" />
                            <script type="text/javascript">
                                $(document).ready(function() {
                                    $('.bxslider').bxSlider();
                                });
                            </script>
                            <div class='store_sliderz'>
                                <ul class="bxslider">
                                    <?= $content ?>
                                </ul>
                            </div>
                        </div>
                    <?php } ?>
                <?php } ?>




                <div class="store_name">
                    <img src="<?php
                    foreach ($storedetails as $stdetails)
                        if ($stdetails->name == 'logo')
                            echo $slogo = base_url(STORE_PATH . $stdetails->value)
                            ?>" alt="" />
                    <p>
                        <b><?= lang('label_owner') ?> :</b> <?= $store->username ?>
                        <br /><b><?= lang('label_rating') ?> :</b> <?
                        if ($rating = get_store_ratings($store->id)) {
                            echo $rating['prec'] . '% ' . lang('label_' . $rating['type']);
                        }
                        else
                            echo '-'
                            ?>
                        <?php if(isset($owner)){ ?>
                        <br /><b><?= lang('label_member_since') ?> :</b> <?php
                        $d = explode(' ', $store->ucreate);
                        echo (isset($d[0])) ? $d[0] : '-';
                        ?>
                        <br /><b><?= lang('label_menu_link_package') ?> :</b> <?
                        if ($packagename = get_package_name($store->package_id)) {
                            echo $packagename;
                        }
                        else
                            echo '-'
                            ?>
                        <?php } ?>
                    </p>
                </div>


                <div class="store_info_right">
                    <div class="store_wide_note">
                        <div class="drop_down" style="display:inline-block;">
                            <a><?= lang('label_store') . ' ' . lang('label_menu_link_pages') ?> ( ^ )</a>
                            <ul>
                                <?php
                                $value = explode('+', $values['staticpages']);
                                $inp = 1;
                                if (count($value) > 0) {
                                    foreach ($value as $p => $v) {
                                        $v = trim($v);
                                        if (is_numeric($v)) {
                                            for ($i = $inp; $i <= $v + $inp; $i++) {
                                                ?>
                                                <?php
                                                foreach ($storedetails as $stdetails)
                                                    if ($stdetails->name == "staticpages_$i") {
                                                        $ech = unserialize($stdetails->value);
                                                        ?>
                                                        <li>&raquo; <a href="<?= base_url("store/pages/$store->id/$i") ?>"><?= $ech['title'] ?></a></li>
                                                    <?php } ?>
                                                <?php
                                            } $inp += $i;
                                        } else {

                                            foreach ($storedetails as $stdetails)
                                                if ($stdetails->name == "staticpages_$v") {
                                                    $ech = unserialize($stdetails->value);
                                                    ?>
                                                    <li>&raquo; <a href="<?= base_url("store/pages/$store->id/$v") ?>"><?= lang('label_values_' . $v) ?></a></li>
                                                <?php } ?>
                                            <?php
                                            $inp++;
                                        }
                                        ?>
                                        <?php
                                    }
                                }
                                ?>
                            </ul>

                        </div>

                        <?= lang('label_products') ?> : <b>(<?= count($products) ?>)</b>
                        <?php if ($values['visitorcounter'] == 'true') { ?>
                            <span><?= lang('label_visitors') ?> : <b>(<?= $store->view ?>)</b></span>
                        <?php } ?>
                        <?php if ($values['subemails'] == 'true') { ?>
                            <?= lang('label_subscriber') ?> : <b>(<?= $subcount = get_subscribers_count($store->id) ?>)</b>
                            <?php if (isset($owner) && $subcount > 0) { ?>
                                &nbsp;<a href="<?= base_url('store/subscribers') ?>"><?= lang('label_show_subscribers') ?></a>
                            <?php } ?>
                        <?php } ?>
                        <?php if (isset($owner)) { ?>
                            &nbsp;|&nbsp;<a href="<?= base_url('store/deals') ?>"><?= lang('label_deals') ?></a> <?php
                            $new = get_count_new_deals($store->id);
                            if ($new)
                                echo " : <b>($new)</b>"
                                ?>
                        <?php } ?>
                        <?php if (isset($owner) && $values['sms'] != 'false') { ?>
                            &nbsp;|&nbsp;<a href="<?= base_url('user_sms') ?>">SMS</a>
                        <?php } ?>

                        <?php if (!isset($owner)) { ?>
                            <?php if ($type = user_like_dislike_store($store->id)) { ?>
                                <a class="dislike" style="opacity: 0.38;cursor: default" href="javascript:void(0)"></a>
                                <a class="like" style="opacity: 0.38;cursor: default" href="javascript:void(0)"></a>
                            <?php } else { ?>
                                <a class="dislike" href="<?= base_url('store/dislike/' . $store->id) ?>"></a>
                                <a class="like" href="<?= base_url('store/like/' . $store->id) ?>"></a>
                            <?php } ?>
                        <?php } ?>
                    </div>

                    <div class="social_a">
                        <div class="social_a">
                            <a class="sharefb" href="javascript:void(0)" onclick="
                                            window.open(
                                                    'http://www.facebook.com/sharer/sharer.php?s=100&p[url]=' + location.href + '&p[images][0]=<?= $slogo ?>&p[title]=<?= $sname ?>&p[summary]=<?= (isset($sdescr)) ? $sdescr : '' ?>',
                                                    'facebook-share-dialog',
                                                    'width=626,height=436');
                                            return false;"></a>
                            <a class="sharetw" href="javascript:void(0)" onclick="
                                            window.open(
                                                    'https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent('<?= base_url() ?>') + '&text=' + encodeURIComponent('<?= (isset($sdescr)) ? $sdescr : '' ?>') + '&tw_p=tweetbutton&url=' + encodeURIComponent(location.href),
                                                    'facebook-share-dialog',
                                                    'width=626,height=436');
                                            return false;" ></a>
                                                                    <a class="sharecn" <?php if(isset($owner)){ ?> style="opacity: .3;cursor: default" <?php } ?> href="<?= (isset($owner)) ? 'javascript:void(0)' : base_url("private_messages/send/$store->owner_id") ?>"></a>
                        </div>
                    </div>
                    <div style="clear:both; float:none;"></div>
                </div>
                <div style="clear:both; float:none;"></div>
            </div>

            <div class="store_border">
                <samp>
                    <?php if (isset($owner)) { ?>
                        <a class="store_but" href="<?= base_url('store/edit') ?>"><?= lang('label_edit_your_store') ?></a>
                        <a class="store_but" href="<?= base_url('user/edit/') ?>"><?= lang('label_edit_profile') ?></a>
                        <a class="store_but" href="<?= base_url('store/upgrade/') ?>"><?= lang('label_upgrade_store') ?></a>
                        <a class="store_but" href="<?= base_url('cases/index/store') ?>"><?= lang('label_resloution_center') ?></a>
                    <?php } else { ?>
                        <?php if ($values['subemails'] == 'true') { ?>
                            <?php if (user_subcribe_store($store->id)) { ?>
                                <a class="store_but" href="<?= base_url('store/unsubscribe/' . $store->id) ?>"><?= lang('label_unsubscribe') ?></a>
                            <?php } else { ?>
                                <a class="store_but" href="<?= base_url('store/subscribe/' . $store->id) ?>"><?= lang('label_subscribe') ?></a>
                            <?php } ?>
                        <?php } ?>
                    <?php } ?>

                </samp>
            </div>




            <div style="overflow:hidden;">
                <div class="store_sidebar">
                    <?php if ($values['barcategory'] == 'true') { ?>
                        <div class="store_category">
                            <h5><?= lang('label_store') . ' ' . lang('label_menu_link_categories') ?></h5>
                            <?php
                            $storecats = get_store_cats($store->id);
                            if (is_array($storecats) && count($storecats) > 0) {
                                ?>
                                <ul>
                                    <?php foreach ($storecats as $sct) {
                                        ?>
                                        <li><a href="<?= base_url("store/categories/$store->id/$sct->id") ?>"><?php
                                                $title = unserialize($sct->title);
                                                echo (isset($title[LANG])) ? $title[LANG] : ((LANG == 'ar') ? $title['en'] : $title['ar']);
                                                ?></a></li>
                                    <?php } ?>
                                </ul>
                            <?php } ?>
                            <p></p>
                        </div>
                    <?php } ?>

                    <?php if ($values['searchbox'] == 'true') { ?>
                        <div class="store_category">
                            <h5><?= lang('label_store') . ' ' . lang('label_search') ?></h5>
                            <form class="forms2" action="<?= base_url("store/search/$store->id") ?>" method="post">
                                <div class="text">
                                    <input style="width:140px; padding:6px;" type="text" name="keyword" palceholder="<?= lang('label_search_in') . ' ' . $sname ?>">
                                </div>
                                <div class="submit">
                                    <input style="margin:3px auto 6px;height: 30px;line-height: 30px; font-size:17px;" type="submit" value="<?= lang('label_search') ?>" name="submit" />
                                </div>
                            </form>
                        </div>
                    <?php } ?>
                    <div class="store_adv">
                        <?php if ($values['storead'] == 'true_owner') { ?>
                            <?php
                            $ads = 0;
                            foreach ($storedetails as $stdetails) {
                                if ($stdetails->name == 'storead_1') {
                                    ?>
                                    <a href="javascript:void(0)"><img src="<?= base_url(STORE_PATH . $stdetails->value) ?>" alt="" /></a>
                                    <?php
                                    $ads++;
                                } elseif ($stdetails->name == 'storead_2') {
                                    ?>
                                    <a href="javascript:void(0)"><img src="<?= base_url(STORE_PATH . $stdetails->value) ?>" alt="" /></a>
                                    <?php
                                    $ads++;
                                }
                                ?>
                            <?php } ?>
                            <?php
                            if ($ads != 2) {
                                $adss = get_random_ads(2 - $ads);
                                if ($adss) {
                                    foreach ($adss as $ad) {
                                        ?>
                                        <a href="<?= ($ad->url) ? $ad->url : base_url('pages/view/adv') ?>"><img src="<?= ($ad->image) ? base_url(ADS_PATH . $ad->image) : base_url(ADS_PATH . 'default.png') ?>" alt="" /></a>

                                        <?php
                                    }
                                }
                            }
                            ?>
                        <?php } else { ?>
                            <?php
                            $ads = get_random_ads(2);
                            if ($ads) {
                                foreach ($ads as $ad) {
                                    ?>
                                    <a href="<?= ($ad->url) ? $ad->url : base_url('pages/view/adv') ?>"><img src="<?= ($ad->image) ? base_url(ADS_PATH . $ad->image) : base_url(ADS_PATH . 'default.png') ?>" alt="" /></a>

                                    <?php
                                }
                            }
                            ?>
                        <?php } ?>
                    </div>
                </div>

                <div class="store_products">
                    <div class="all_stores"><div>
                            <h4><?= lang('label_all') . ' ' . lang('label_products') ?>
                                <input class="store_but" style="float: right;margin-top: 6px;cursor: pointer;" type="button" value="<?= lang('label_more') . ' ...' ?>" onclick="location.href = '<?= base_url("products/stores/$store->id") ?>'">
                                <?php if (isset($owner)) { ?>
                                    <input class="store_but" style="float: right;margin-top: 6px;cursor: pointer;" type="button" value="<?= lang('label_add_new_product') ?>" onclick="location.href = '<?= base_url("products/add") ?>'">
                                <?php } ?>
                            </h4>

                            <div></div>


                            <?php if ($products) { ?>

                                <ul class="all_stores_pro_ul">
                                    <?php
                                    foreach ($products as $product) {
                                        $images = unserialize($product->images);
                                        $nodef = TRUE;
                                        ?>
                                        <li>
                                            <div>
                                                <a href="<?= base_url('products/view/' . $product->id) ?>">
                                                    <img src="<?php
                                                    if (count($images) > 0) {
                                                        foreach ($images as $k => $v) {
                                                            if ($v[1] == 'yes') {
                                                                $nodef = false;
                                                                $defimage = $v[0];
                                                                echo base_url(PRODUCT_PATH . $v[0]);
                                                            }
                                                        } if ($nodef) {
                                                            base_url(PRODUCT_PATH . $images[0][0]);
                                                            $defimage = $images[0][0];
                                                        }
                                                    } else {
                                                        echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) . '/' . APPPATH . 'views/' . $this->themes->Cms_themes() . '/images/noimage_' . LANG . '.gif';
                                                    }
                                                    ?>" alt="" ></a>
                                                <span class="price"><b><?= lang('label_rial') ?></b><br /><?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?></span>
                                                <?php if ($product->discount_precentage > 0) { ?>
                                                    <span class="stitch"><b> &nbsp;%</b><br /><?= $product->discount_precentage ?></span>
                                                <?php } ?>
                                            </div>
                                            <h4><a href="<?= base_url('products/view/' . $product->id) ?>"><?= $product->name ?></a></h4>
                                            <a class="shipping">: <?php
                                                if ($product->shiping_weghite <= $maxwight) {
                                                    echo (double) $shipingprice;
                                                } else {
                                                    $weghit = (double) $maxwight - 10;
                                                    echo $shipingprice + $priceforunit * $weghit;
                                                }
                                                ?> <?= lang('label_rial') ?></a>
                                            <a class="buynow" href="<?= base_url('products/view/' . $product->id) ?>">&nbsp;</a>
                                        </li>
                                    <?php } ?>
                                </ul>
                            <?php } else { ?>
                                <div style="text-align: center; width: 100%; color: red"><h3><?= lang('message_no_products') ?></h3></div>
                            <?php } ?>


                        </div></div>

                    <div class="all_stores"><div>
                            <h4><?= lang('label_product_special') ?>
                                <?php if (isset($owner)) { ?>
                                    <input class="store_but" style="float: right;margin-top: 6px;cursor: pointer;" type="button" value="<?= lang('label_add_new_product') ?>" onclick="location.href = '<?= base_url("products/add") ?>'">
                                <?php } ?>
                            </h4>
                            <div></div>

                            <?php if ($specialproducts) { ?>

                                <ul class="all_stores_pro_ul">
                                    <?php
                                    foreach ($specialproducts as $product) {
                                        $images = unserialize($product->images);
                                        $nodef = TRUE;
                                        ?>
                                        <li>
                                            <div>
                                                <a href="<?= base_url('products/view/' . $product->id) ?>">
                                                    <img src="<?php
                                                    if (count($images) > 0) {
                                                        foreach ($images as $k => $v) {
                                                            if ($v[1] == 'yes') {
                                                                $nodef = false;
                                                                $defimage = $v[0];
                                                                echo base_url(PRODUCT_PATH . $v[0]);
                                                            }
                                                        } if ($nodef) {
                                                            base_url(PRODUCT_PATH . $images[0][0]);
                                                            $defimage = $images[0][0];
                                                        }
                                                    } else {
                                                        echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) . '/' . APPPATH . 'views/' . $this->themes->Cms_themes() . '/images/noimage_' . LANG . '.gif';
                                                    }
                                                    ?>" alt="" /></a>
                                                <span class="price"><b><?= lang('label_rial') ?></b><br /><?= ($product->discount_precentage > 0) ? $product->discount_price : $product->price; ?></span>
                                                <?php if ($product->discount_precentage > 0) { ?>
                                                    <span class="stitch"><b> &nbsp;%</b><br /><?= $product->discount_precentage ?></span>
                                                <?php } ?>
                                            </div>
                                            <h4><a href="<?= base_url('products/view/' . $product->id) ?>"><?= $product->name ?></a></h4>
                                            <a class="shipping">: <?php
                                                if ($product->shiping_weghite <= $maxwight) {
                                                    echo (double) $shipingprice;
                                                } else {
                                                    $weghit = (double) $maxwight - 10;
                                                    echo $shipingprice + $priceforunit * $weghit;
                                                }
                                                ?> <?= lang('label_rial') ?></a>
                                            <a class="buynow" href="<?= base_url('products/view/' . $product->id) ?>">&nbsp;</a>
                                        </li>
                                    <?php } ?>
                                </ul>
                            <?php } else { ?>
                                <div style="text-align: center; width: 100%; color: red"><h3><?= lang('message_no_products') ?></h3></div>
                            <?php } ?>

                        </div></div>
                </div>
            </div>
        </div>
        <!-- End Page -->
        <script>
                                $(function() {
                                    $('.drop_down').hover(
                                            function() {
                                                //show its submenu
                                                $('ul', this).slideDown(150);
                                            },
                                            function() {
                                                //hide its submenu
                                                $('ul', this).slideUp(150);
                                            }
                                    );
                                });
        </script>
    <?php } else { ?>

        <?php if ($store->owner_id == $this->user_id) { ?>
            <h1><span class="ico_signin"></span><?= lang('label_menu_link_store_underconstruction') ?></h1>
            <ul class="breadcrumb">
                <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
                <li><a href="<?= base_url('index/stores') ?>"><?= lang('label_menu_link_stores') ?></a></li>
                <li><?= lang('label_menu_link_store_underconstruction') ?></li>
            </ul>
            <div class="page">
                <div class="unsaved">
                    <img src="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/images/unsaved.png" alt="" />
                    <br /><?= str_replace('%link%', base_url('store/edit'), lang('message_start_your_store')) ?>
                </div>
                <br /><br /><br /><br />
            </div>
        <?php } else { ?>
            <h1><span class="ico_signin"></span><?= lang('label_menu_link_store_underconstruction') ?></h1>
            <ul class="breadcrumb">
                <li><a href="<?= base_url() ?>"><?= lang('label_home') ?></a></li>
                <li><a href="<?= base_url('index/stores') ?>"><?= lang('label_menu_link_stores') ?></a></li>
                <li><?= lang('label_menu_link_store_underconstruction') ?></li>
            </ul>
            <div class="page">
                <div class="unsaved">
                    <img src="<?php echo str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']) ?>/<?php echo APPPATH ?>views/<?php echo $this->themes->Cms_themes() ?>/images/unsaved.png" alt="" />
                    <br /><?= lang('message_store_underconstruction') ?>
                </div>
                <br /><br /><br /><br />
            </div>
        <?php }
        ?>
    <?php } ?>
<?php } ?>


